package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

type A struct {
	privateKey string
	appId      string
	NotifyURL  string
	ReturnURL  string
}

func Alipay() *A {
	return &A{
		privateKey: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCxA/fsAZPTv/3E1YTYa1HcgDbCb+pO5Cr3iRjiAmecIdnu4ARtho1Db2PU84T4Bf568euPPTwvw4JhtqXA0ZZIgnjRgX9eRGc7ktiwDXb1LIQJtGCvA2pGFXX5Yy6c8jHXiwJgld5OGlXKAzZcDchqTX4qIu010uH6PfgyyJm6E/RYINmT9ECR/LfHEtjmvWuka4E1Gdo6NAGQ/eVrdgWGfHNFVZmw9kc6MvyKUZ30mqUw+nYFHSCNNVMPgQMYTYGY0aZq6fEdbyUmLphMlXfBMCdQYmJW7WaQefArX6oK3a8QdUIDwPCgT7mHLICiilP01ermhORJnRVWRHL+Y99vAgMBAAECggEALx3DS8pPsrkTruS2a3SFYY+vA6oOT9ljpmeTe/Tv5xsLiw2NoCmESELJ69C1v964kbj63jGKZ5w+hAu9qskem0Y/KmSxpkHGyJCZpKKw2ylyK7MbWPoru2PS9wJzUcsVgS27AEJj3Z4c35xjR7VTdxgRUN3jDcSH6be87KeAY4qhxKAK5jYjWaJHUyPtM4AjKuRykkwbWOdsyBVS8G0GBXUDFkNjBdrIi0Pw8KnrqsRzpzdSbLRUqIa6foyqqejxLA1oDderzODD+4h2dNJlLyjkZl5cYvkNw21Pl4MSDFUlEEgoJm0K/jtI1QkALYjwasZbOcnjWB+YGAMY4r4uIQKBgQD0TwFhAvBhCIK+pFgibgEZKsp92DVHYuK8QIpSt3WMpwnkbScxyXvUz0wOug1uykLWSx+s1IYrEKQdYiznd/rXO+PiJmu8QbBFFEUsA+nKJR0HdORWjKAbWjBpNDUCd87DA1Eg7F9X/f4m/i5H6xch9UUmbOJsRASg5gLrn7B3pQKBgQC5fJA+pzB2wc59fPcrxFMHs+0Cy1S6r1v9DyTPJAGNNMGBHmlS7ei2imsBeEnfnSmh/uB0t5BsSYFf3XoC/gRt05YueIHSaCceHR4MsqyWhFQdOgVfa9Q9O+CkEdZG15NVZpXUNlvDjlOU/vUa29Qzh1yNSwJBDBF+1aV8P4sugwKBgDLMdrHwRYE3ns/7JiRKkUnlXuNZ4IIuaozQMrLOWM/dL65ij+LHTUtLqznor8BYqBsc1cI/EoLD3AwMDOA4T10Po+uzJ3WmhvtmIpfrXGJe4zFYud3RMb1ePHCznU4dEU31U5ov7AdE1eLPuVnU5SN3d2BtBYuTfQ7jpLnPo4bNAoGBAIJGH1UxvZMbCXkPZNYjfCFj2Gnm/ypi8Vup4DNv2Xsge2vBPT4WhCR40TDmGBRq4Iu7ZE/1gQTdF3WKKyCg4eF1Avy+fIeXySmYT7uhXiAU7rLcRlu/cwBS5rK1KGb3D66ib0btqsONWdzCuMlVbhOG1ZUTApFG9Z68VQ8P3iQbAoGBAIF8Oj6smmt7FdPwI1MVYNbvILMwGccwz8z9zddcFA0mrQd/Uv/9dnwxngbE90JP5u95MQN2L2Igbortin6CB3njDCUuAqm9SkVI2tW7A66MJlT6ByfI7p3Fv8LrWtOkAwYhd6QxqiEwj5G2MCUjTaAJRf/3cl6950bnyeZ0ZPB9",
		appId:      "9021000142690931",
		NotifyURL:  "https://4a0a3dc3.r12.cpolar.top/ordercall",
		ReturnURL:  "https://gitee.com/",
	}
}
func (a *A) ALiPays(Subject, OutTradeNo, TotalAmount string) string {
	var privateKey = a.privateKey // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	var client, err = alipay.New(a.appId, privateKey, false)
	if err != nil {
		fmt.Println(err)
	}
	var p = alipay.TradeWapPay{}
	p.NotifyURL = a.NotifyURL
	p.ReturnURL = a.ReturnURL
	p.Subject = Subject
	p.OutTradeNo = OutTradeNo
	p.TotalAmount = TotalAmount
	p.ProductCode = "QUICK_WAP_WAY"

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
	}

	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	fmt.Println(payURL)
	return payURL
}
